package Utilitys;

import com.alibaba.druid.pool.DruidDataSourceFactory;
import org.apache.commons.dbutils.QueryRunner;

import javax.sql.DataSource;
import java.io.FileInputStream;
import java.util.Properties;

public class DruidMySql {
    /**
     * 获取连接对象Connection
     */
    public static QueryRunner getQueryRunner() {
        /*
        创建properties对象
        */
        Properties properties = new Properties();
        try{
            /*
                读取properties文件
                 */
            properties.load(new FileInputStream("F:\\kaifamiao.1\\java基础\\Code\\KaiFaMiao\\JavaWeb\\Servelit10.13\\io\\druid.properties"));
                /*
                获取连接方法
                 */
            DataSource dataSource = DruidDataSourceFactory.createDataSource(properties);
            return new QueryRunner(dataSource);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
}

